#!/usr/bin/env python

import sys
from portfolio import *

class text_portfolio(portfolio):
  def __init__(self, uname, password, portfolionumber=1, fielddelim="\t\t", stockdelim="\n\n",
               transdelim="\n", transactioninfo=[], performanceInfo=[] ):
    self.fielddelim = fielddelim
    self.transdelim = transdelim
    self.stockdelim = stockdelim
    portfolio.__init__(self, uname, password, portfolionumber)
    self.transactioninfo = transactioninfo
    self.print_transactions()

  #TODO, doesn't seem to be picking up sold stock
  def print_transactions(self):
    translist = self.portfolio_transactions.transactions.keys()
    translist.sort()
    for compname in translist:
      print "compname: ", compname
      for transaction in self.portfolio_transactions.transactions[compname]:
          for i in self.transactioninfo:
            if i == "companyName":
              sys.stdout.write(transaction["companyName"] + self.fielddelim )
            elif i == "date":
              sys.stdout.write(transaction["date"] + self.fielddelim )
            elif i == "transaction":
                sys.stdout.write(transaction["transaction"] + self.fielddelim )
            elif i == "pricePerShare":
              sys.stdout.write(transaction["pricePerShare"] + self.fielddelim )
            elif i == "numShares":
              sys.stdout.write(transaction["numShares"] + self.fielddelim )
            elif i == "commission":
              sys.stdout.write(transaction["commission"] + self.fielddelim )
            sys.stdout.write(self.transdelim)


#if __name__ == "__main__":
#  myportfolio = text_portfolio("username@gmail.com", "password")
#  myportfolio.print_transactions()
